package ui 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import ui.button.GCButton;
	
	/**
	 * ...
	 * @author Jason Won
	 */
	public class Scrollbar extends Sprite
	{
		// Components
		private var _slider:Slider;
		private var _upArrow:GCButton;
		private var _downArrow:GCButton;
		
		private var scrollSpeed:Number = .1;
		
		
		
		/** Constructor **/
		public function Scrollbar(length:int) 
		{
			_upArrow = new GCButton(onArrowPressed);
			_upArrow.loadGraphic(GCResources.up_arrow, 20, 20);
			_downArrow = new GCButton(onArrowPressed);
			_downArrow.loadGraphic(GCResources.down_arrow, 20, 20);
			
			_slider = new Slider(_upArrow.width, length - _upArrow.height - _downArrow.height); 
			
			init();
		}
		
		private function init():void
		{
			// Adjust component locations
			_slider.y = _upArrow.height;
			_downArrow.y = _slider.y + _slider.height;
            
			// Add the components to visual
			addChild(_slider);
            addChild(_upArrow);
			addChild(_downArrow);
		}
		
		
		/** GET FUNCTIONS **/
		public function get percent():Number
		{
			return _slider.percent;
		}
		
		/** SET FUNCTIONS **/
		public function set percent(percentage:Number):void
		{
			_slider.percent = percentage;
		}
		
		/** Event Handlers **/
		
		// Executes when the arrows are pressed
		private function onArrowPressed(event:MouseEvent):void
		{
			var dir:int = (event.target == _upArrow) ? -1 : 1;
			_slider.percent += dir * scrollSpeed;
		}
		
		
		/** Public Functions **/
		public function changeScroll(dir:int):void
		{
			_slider.percent += dir * scrollSpeed;
		}
		
	}
}


        
        
        /**
         * Override the add and remove event listeners, so that SliderEvent.CHANGE events will be 
         * subscribed to the Slider directly.
         * 
         * There is issues with this however, Event.CHANGE events will get subscribed directly too Slider as well.
         */
		
		 /*
        public override function addEventListener( type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false ):void
        {
            if ( type === SliderEvent.CHANGE )
            {
                slider.addEventListener( SliderEvent.CHANGE, listener, useCapture, priority, useWeakReference );
                return;
            }
            super.addEventListener( type, listener, useCapture, priority, useWeakReference );
        }
        public override function removeEventListener( type:String, listener:Function, useCapture:Boolean=false ):void
        {
            if ( type === SliderEvent.CHANGE )
            {
                slider.removeEventListener( SliderEvent.CHANGE, listener, useCapture );
                return;
            }
            super.removeEventListener( type, listener, useCapture );
        }
    }
}*/